﻿CREATE proc thuan_qtphannhommenu_capnhomnguoidung  
@UserID int,  
@MaNhomUser int  
as  
if exists (select * from QuanTri_PhanNhomNguoiDung Where UserID=@UserID and MaNhomUser=@MaNhomUser)  
begin  
select ErrCode=0  
end  
else  
begin  



insert into QuanTri_PhanNhomNguoiDung(UserID,MaNhomUser) values(@UserID,@MaNhomUser)  
declare @IDPhanNhomNguoiDung as int
select @IDPhanNhomNguoiDung=@@IDENTITY
insert into QuanTri_EditUserRoleInGroup (IDPhanNhomNguoiDung,IDCapQuyen,IDPhanNhomMenu,Quyen_CapNhat,Quyen_Xem,Quyen_Xoa)  
select distinct e.ID as IDPhanNhomNguoiDung, a.ID as IDCapQuyen,c.ID as IDPhanNhomMenu,c.Quyen_CapNhat,c.Quyen_Xem,c.Quyen_Xoa
from QuanTri_CapQuyenNguoiDungSuDungMenu a,DanhMuc_NhomMenuNguoiDung b,QuanTri_PhanNhomMenu c,
DanhMuc_NhomNguoiDung d ,QuanTri_PhanNhomNguoiDung e
Where a.MaNhomMenuND=b.MaNhomMenuND and b.MaNhomMenuND=c.MaNhomMenuND and a.MaNhomUser=d.MaNhomUser and d.MaNhomUser=e.MaNhomUser
and e.ID=@IDPhanNhomNguoiDung
select ErrCode=1  
end